home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / catlog / source / divide.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  7KB  |  268 lines

  1. /*
  2.     NIFTYのLOG整理                divide.c
  3.                     by GHH01217 山先
  4.     $Header: DIVIDE.Cv  1.2  93/02/12 22:46:44  山先  Exp $
  5. */
  6.  
  7. #include    "log.h"
  8.  
  9. void    check_drive_space_23( )
  10. {
  11.             int            drive , drive_free;
  12.     struct    _disk_space info;
  13.  
  14.     if ( output_path[ 1 ] == ':' ) {
  15.         drive = toupper( output_path[ 0 ] ) & 0x0f;
  16.     } else {
  17.         drive = 0;    /* カレント drive */
  18.     };
  19.     info = _dos_get_disk_space( drive );
  20.     drive_free = info.nsectors * info.free_clusters * info.nbytes;
  21. /*
  22.     printf("%s : %ld\n", output_path , drive_free);
  23. */
  24.  
  25.     if ( drive_free < 82*310 ) {
  26.         printf("\nディスク・スペースが足りません。");
  27.         exit( 1 );
  28.     };
  29. }
  30.  
  31. extern    int    mkdir( const char *path );
  32.  
  33. /************************************************/
  34. /* output_pathを検査してディレクトリがない場合は作る */
  35. /************************************************/
  36. void    check_and_make_output_path( const char *forum_name )
  37. {
  38.     int        count , sw;
  39.     char    full[ 128 ],*p1;
  40.  
  41.     strcpy( full , forum_name );
  42.  
  43. #ifdef    TEST
  44.     printf("<%s>のディレクトリの有無をチェックします。\n",full);
  45. #endif
  46.  
  47.     count = 0;
  48.  
  49.     p1 = full;
  50.     if ( p1[1] == ':' )    p1 += 2;
  51.     if ( *p1 == '\\' )    p1++;
  52.     while ( *p1 ) {
  53.         sw = TRUE;
  54.         while ( *p1 != '\\' ) {    /* 最初の \ を探す */
  55.             if ( *p1 == '\0' ) {
  56.                 sw = FALSE;        break;
  57.             };
  58.             p1++;
  59.         };
  60.         if ( sw == FALSE )    break;
  61.         *p1 = '\0';
  62.         if ( chdir( full ) < 0 ) {
  63.             if ( mkdir( full ) != 0 ) {
  64.                 sprintf(str,"<%s>でディレクトリ<%s>が作れません。",
  65.                     forum_name,full
  66.                 );
  67.                 error_return( str );    return;
  68.             };
  69.         };
  70.         *p1 = '\\';        p1++;        count++;
  71.     };
  72.     strcpy( full , forum_name );
  73.     p1 = full;
  74.     if ( p1[1] == ':' )    p1 += 2;
  75.     *p1 = '\0';
  76.     strcat( full  , ".." );
  77.     while ( count > 0 ) {        chdir( full );    count--;    };
  78. }
  79.  
  80. /*****************************/
  81. /* 各ディレクトリの tmp file name */
  82. /*****************************/
  83. static    void    set_id_tmp_file_name( char *forum , int num , char *collect)
  84. {
  85.     char    path[ 128 ];
  86.  
  87.     switch( num ) {
  88.         case BILL:    strcpy(  path , "BILL\\" );
  89.                     strcat(  path , BILL_FILE_NAME );
  90.                     strcat(  path , ".tmp" );                            break;
  91.         case MAIL:
  92.         case ALL_MAIL:
  93.             if ( MakeUpMAILInto1FileSw == YES ) {
  94.                 sprintf( path , "NIFMAIL\\catlog%2d.tmp" , MAIL );
  95.             } else {
  96.                 sprintf( path , "NIFMAIL\\%s.tmp" , forum );
  97.             };
  98.             break;
  99.         case CLIP:    strcpy(  path , "CLIP\\catlog-9.tmp" );                break;
  100.         case HP:    sprintf( path , "HP\\%s\\%s.tmp",forum,forum);        break;
  101.         case PATIO:    sprintf( path , "PATIO\\%s\\%s.tmp",forum,forum);    break;
  102.         case LIB:    if ( output_DL_List_path[ 0 ] != '\0' ) {
  103.                         strcpy( file_name , output_DL_List_path );
  104.                         strcat( file_name , forum );
  105.                         strcat( file_name , "\\" );
  106.                         check_and_make_output_path( file_name );
  107.                         sprintf( path , "catlog%2d.tmp",num);
  108.                         strcat( file_name , path );
  109.                         return;    /* 終了 */
  110.                     } else {
  111.                         sprintf( path , "%s\\catlog%2d.tmp",forum,num);
  112.                     };
  113.                     break;
  114.         case COLLECT_ID:
  115.                     sprintf( path , "COLLECT\\%s.tmp" , collect );    break;
  116.         case COLLECT_LIB:
  117.                     if ( output_DL_List_path[ 0 ] != '\0' ) {
  118.                         strcpy( file_name , output_DL_List_path );
  119.                         strcat( file_name , "COLLECT\\" );
  120.                         strcat( file_name , collect );
  121.                         strcat( file_name , "\\" );
  122.                         check_and_make_output_path( file_name );
  123.                         sprintf( path , "catlog%2d.tmp",num);
  124.                         strcat( file_name , path );        return;    /* 終了 */
  125.                     } else {
  126.                         sprintf( path , "COLLECT\\%s\\catlog%2d.tmp",
  127.                             collect,
  128.                             num
  129.                         );
  130.                     };
  131.                     break;
  132.         default:    sprintf( path , "%s\\catlog%2d.tmp",forum,num);
  133.                     file_name_space_0( path );                            break;
  134.     };
  135.     strcpy( file_name , output_path );
  136.     strcat( file_name , path );
  137. }
  138.  
  139. static    int        divide_loop_check(
  140.     char    *last_forum ,        char    *forum ,
  141.     char    *last_collect ,        char    *collect ,
  142.     int        last_mes_num ,        int        mes_num
  143. ) {
  144.     if ( *last_forum == '\0' )                            return( YES );
  145.  
  146.     if ( mes_num == COLLECT_ID || mes_num == COLLECT_LIB ) {
  147.         if ( last_mes_num != mes_num )                    return( YES );
  148.         if ( strcmp( last_collect , collect ) != 0 )    return( YES );
  149.     } else {
  150.         if ( last_mes_num == COLLECT_ID || last_mes_num == COLLECT_LIB )
  151.                                                         return( YES );
  152.         if ( strcmp( last_forum , forum ) != 0 )        return( YES );
  153.         if ( last_mes_num != mes_num )                    return( YES );
  154.     };
  155.     return( NO );
  156. }
  157.  
  158. /*******************************/
  159. /* 発言毎にディレクトリに切り分ける */
  160. /*******************************/
  161. /*
  162.     CATLOG.TMP には、次の順番に標準のデータが登録されている
  163.         CATLOG.TMP の発言の区切り
  164.         フォーラム名
  165.         会議室番号
  166.         発言番号
  167.         発言の日付
  168.         コメント先番号
  169.         発言者のID
  170.         forum_name_line[ 80 ];
  171.         forum_sub_name_line[ 80 ];
  172. */
  173.  
  174. static    void    divide_loop( )
  175. {
  176.     int        sw , mes_num , last_mes_num;
  177.     char    forum[ 12 ],collect[ 12 ];
  178.     char    last_forum[ 12 ],last_collect[ 12 ];
  179.  
  180.     GET_LINE;                    /* *****log整理 */
  181.  
  182.     *last_forum = *last_collect = '\0';
  183.     last_mes_num = mes_num = 0;
  184.     sw = FALSE;
  185.     forever {
  186.         check_pool_delete_start = PresentStrPtr;
  187.         GET_LINE;                /* Forum名 or ID名 */
  188.         /* 以下は実行しないはずなのだが……… */
  189.         if ( PresentStrLen < 1 || 8 < PresentStrLen ) {
  190.             present_str_print();
  191.             strcpy(str,"divideでおかしな行 ↑ をみつけました。FORUM名");
  192.             error_bug( str );
  193.         };
  194.         present_str_copy( forum );
  195.         GET_LINE;                /* 会議室番号 */
  196.         /* 以下は実行しないはずなのだが……… */
  197.         if ( PresentStrLen > 2 ) {
  198.             present_str_print();
  199.             strcpy(str,"divideでおかしな行 ↑ をみつけました。MES_NUM\n");
  200.             error_bug( str );
  201.         };
  202.         mes_num = atoi( PresentStrPtr );
  203.  
  204.         GET_LINE;                /* 発言番号 */
  205.         hatsugen_number = atoi( PresentStrPtr );
  206.         GET_LINE;                /* 発言の日付 */
  207.         GET_LINE;                /* コメント先番号 */
  208.         GET_LINE;                /* 発言者のID */
  209.         if ( PresentStrLen != 0 ) {            /* IDによる収集の発言である */
  210.             present_str_copy( collect );
  211.         } else {
  212.             *collect = '\0';
  213.         };
  214.  
  215.         /*
  216.             Collect_ID or Collect_ID_LIB の場合、collect の一致
  217.             その他の場合、forum , mes_num の一致
  218.         */
  219.         if ( divide_loop_check(
  220.                 last_forum ,   forum ,
  221.                 last_collect , collect ,
  222.                 last_mes_num , mes_num
  223.             ) == YES
  224.         ) {
  225.             if ( *last_forum != '\0' ) fclose( catlog_fpo );
  226.             /* open out put file */
  227.             set_id_tmp_file_name( forum , mes_num , collect );
  228.             check_and_make_output_path( file_name );
  229.             if ( (catlog_fpo=fopen( file_name , "ab" ))==NULL ) {
  230.                 error_open_file( "divide_loop" );        error_end();
  231.             };
  232.             strcpy( last_forum , forum );
  233.             last_mes_num = mes_num;
  234.             strcpy( last_collect , collect );
  235.         };
  236.         GET_LINE2 break;
  237.         while ( strncmp( PresentStrPtr , "*****log整理" , 12 ) != 0 ) {
  238.             GET_LINE2 {    sw = TRUE;    break;    };
  239.         };
  240.  
  241.         /* disk full のテストを行う */
  242.         check_drive_space_23( );
  243.  
  244.         if ( catlog_fwrite( ) == 0 ) {
  245.             sprintf(str,"divide_loop 書き込みが出来ませんでした");
  246.             error_return( str );    break;
  247.         };
  248.         if ( sw == TRUE ) break;
  249.     };
  250.     fclose( catlog_fpo );
  251. }
  252.  
  253. void    divide_main()
  254. {
  255.     size_t    fsize;
  256.  
  257.     set_tmp0_file_name( file_name );
  258.     if ( (fsize = _get_file_size( file_name ) ) > 100 ) {
  259.         initial_check_pool( fsize , NO );
  260.             divide_loop( );
  261.         end_check_pool();
  262.     };
  263.  
  264.     /* 最後に巨大なファイルの削除を行う */
  265.     delete_tmp0_file();
  266. }
  267.  
  268.